package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.bean.Pay;
import com.liao.dao.PayDao;
import com.liao.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PayServiceImpl implements PayService {

    @Autowired
    private PayDao payDao;

    @Override
    public PageResult<Pay> queryPayListByPage(Integer currentPage, Integer pageSize, String accountName) throws Exception {
        PageHelper.startPage(currentPage, pageSize);
        List<Pay> payList = payDao.selectPayListByPage(accountName);
        PageInfo pageInfo = new PageInfo(payList);
        return new PageResult<>(0, Msg.PAY_QUERY_SUCCESS, pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void deletePayById(String payId) throws Exception {
        payDao.deletePayById(payId);
    }

    @Override
    public void addPay(String payAccount, String accountName, String operater, String payMoney) throws Exception {
        Pay pay = new Pay();

        pay.setPayAccount(payAccount);
        pay.setAccountName(accountName);
        pay.setOperater(operater);
        pay.setPayMoney(payMoney);

        payDao.addPay(pay);
    }

    @Override
    public void updatePay(Integer payId, String payAccount, String accountName, String operater, String payMoney) throws Exception {
        Pay pay = new Pay();

        pay.setPayId(payId);
        pay.setPayAccount(payAccount);
        pay.setAccountName(accountName);
        pay.setOperater(operater);
        pay.setPayMoney(payMoney);

        payDao.updatePay(pay);
    }
}
